package com.aya;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.*;
import org.springframework.stereotype.Component;

@Activate(group = Constants.PROVIDER)
public class AyaDubboExceptionFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        final Result invoke = invoker.invoke(invocation);
        if(invoke.hasException()){
            final Throwable exception = invoke.getException();
            if(exception.getClass().equals(AyaCommonException.class)){
//                return new RpcResult(exception);
                throw (AyaCommonException)exception;
            }
        }
        return invoke;
    }
}
